<?php
require_once('../../config.php');
require_once('./prontolib.php');

require_login();

//Make sure we are an admin
if (!is_siteadmin()) {
   print_error(get_string('accessdenied','admin'));
}

$paramlogname = required_param('logname', PARAM_NOTAGS);

//Always strip off path if passed - we only get files from log dir
$logname = basename($paramlogname);

$fullName = PRONTO_LOGS_DIR . "/" . $logname . ".log";

if (file_exists($fullName)){
   header("Content-type: application/octet-stream" );
   header("Content-Disposition: attachment; filename=".basename($fullName));
   readfile ($fullName);
   pronto_audit_log(DOWNLOAD_LOG, 'download-log.php?logname=' . $paramlogname);
}else{
   echo "Invalid Log File: " . $logname;
}